TEMPORALS
Photo by Barbara Verge on Unsplash
Mother is the name for God in the lips and hearts of little children….
— William Makepeace Thackeray
url_root <- "https://raw.githubusercontent.com/UN-AVT/kamino-source/main/sources/0-shared/data/"
url_file <- "maternal-mortality/maternal-mortality-slope-chart.csv"
url <- paste0(url_root, url_file)
df <- read.csv(url, header = TRUE)
df
# Filter for year and continent
maternal_mortality_africa_df <- df %>%
filter(Year %in% c(2000, 2005, 2010, 2015) &
Continent %in% c("Africa", "World"))
entity_list_africa <- c("Angola", "Algeria","Cameroon", "Ethiopia", "Ghana", "Kenya" , "Rwanda", "Senegal", "Somalia", "South Sudan", "Sudan", "Tunisia", "Uganda", "Zimbabwe", "World")
maternal_mortality_africa_df <- maternal_mortality_africa_df %>%
filter(Entity %in% entity_list_africa)
# Filter for year and continent
maternal_mortality_asia_df <- df %>%
filter(Year %in% c(2000, 2005, 2010, 2015) &
Continent %in% c("Asia", "World"))
entity_list_asia <- c("Afghanistan", "Armenia","Bangladesh", "Cambodia", "China", "India" , "Japan", "Kazakhstan", "Kuwait", "Sri Lanka", "United Arab Emirates", "Vietnam", "World")
maternal_mortality_asia_df <- maternal_mortality_asia_df %>%
filter(Entity %in% entity_list_asia)
maternal_mortality_asia_df
maternal_mortality_africa_df
Create ordered factor for Year
# Create ordered factor for year
maternal_mortality_africa_df$Year <- factor(maternal_mortality_africa_df$Year, ordered = TRUE, levels = c("2000", "2005", "2010", "2015"))
maternal_mortality_asia_df$Year <- factor(maternal_mortality_asia_df$Year, ordered = TRUE, levels = c("2000", "2005", "2010", "2015"))
maternal_mortality_asia_df
maternal_mortality_africa_df
Side-by-side comparison between a few African and Asian countries.
color_palette_africa <- c("Angola" = "#cccccb",
"Algeria" = "#cccccb",
"Cameroon" = "#cccccb",
"Ethiopia" = "#cccccb",
"Ghana" = "#cccccb",
"Kenya" = "#cccccb",
"Rwanda" = "#cccccb",
"Senegal" = "#cccccb",
"Somalia" = "#cccccb",
"South Sudan" = "#cccccb",
"Sudan" = "#cccccb",
"Tunisia" = "#cccccb",
"Uganda" = "#d8472b",
"Zimbabwe" = "#cccccb",
"World" = "#7dbfe6")
color_palette_asia <- c("Afghanistan" = "#cccccb",
"Armenia" = "#cccccb",
"Bangladesh" = "#cccccb",
"Cambodia" = "#cccccb",
"China" = "#cccccb",
"India" = "#cccccb",
"Japan" = "#cccccb",
"Kazakhstan" = "#cccccb",
"Sri Lanka" = "#cccccb",
"United Arab Emirates" = "#cccccb",
"Vietnam" = "#cccccb",
"Kuwait" = "#d8472b",
"World" = "#7dbfe6")
slope_specs <- list(
# move the x axis labels up top
scale_x_discrete(position = "top"),
theme_bw(),
# Format tweaks
# Remove the legend
theme(legend.position = "none"),
# Remove the panel border
theme(panel.border = element_blank()),
# Remove just about everything from the y axis
theme(axis.title.y = element_blank()),
theme(axis.text.y = element_blank()),
theme(panel.grid.major.y = element_blank()),
theme(panel.grid.minor.y = element_blank()),
# Remove a few things from the x axis and increase font size
theme(axis.title.x = element_blank()),
theme(panel.grid.major.x = element_blank()),
theme(axis.text.x.top = element_text(size=12)),
# Remove x & y tick marks
theme(axis.ticks = element_blank()),
# Format title & subtitle
theme(plot.title = element_text(size=16, face = "bold")),
theme(plot.subtitle = element_text())
)
v1 <- ggplot(data = maternal_mortality_africa_df, aes(x = Year, y = Maternal_Mortality_Ratio, group = Entity)) +
geom_line(aes(color = Entity), size = 0.5, alpha = 1) +
geom_text_repel(data = maternal_mortality_africa_df %>% filter(Year == "2000"),
aes(label = paste0(Entity)) ,
force = 1,
hjust = "left",
fontface = "bold",
size = 3.5,
nudge_x = -.5,
direction = "y",
segment.color = "gray") +
geom_text_repel(data = maternal_mortality_africa_df %>% filter(Year == "2015"),
aes(label = paste0(Entity)),
force = 1,
hjust = "right",
fontface = "bold",
size = 3.5,
nudge_x = .5,
direction = "y",
segment.color = "gray") +
geom_point(aes(fill = Entity), shape = 21, color="white", size = 2, stroke = 0.75, alpha = 1) +
# geom_text(aes(label = Maternal_Mortality_Ratio), color="black", size = 2.5, alpha = 1) +
geom_text_repel(aes(label = Maternal_Mortality_Ratio), color="black", size = 3.5, alpha = 1,
force = 1,
hjust = "center",
#fontface = "bold",
size = 3.0,
# nudge_x = 0,
direction = "y",
segment.color = "gray") +
scale_fill_manual(values = color_palette_africa) +
scale_color_manual(values = color_palette_africa) +
slope_specs +
labs(
title = "Maternal Mortality by Country in Africa",
subtitle = "Maternal deaths per 100,000 live births.",
caption = "source: Our World in Data"
)
v2 <- ggplot(data = maternal_mortality_asia_df, aes(x = Year, y = Maternal_Mortality_Ratio, group = Entity)) +
geom_line(aes(color = Entity), size = 0.5, alpha = 1) +
geom_text_repel(data = maternal_mortality_asia_df %>% filter(Year == "2000"),
aes(label = paste0(Entity)) ,
force = 1,
hjust = "left",
fontface = "bold",
size = 3.5,
nudge_x = -.5,
direction = "y",
segment.color = "gray") +
geom_text_repel(data = maternal_mortality_asia_df %>% filter(Year == "2015"),
aes(label = paste0(Entity)),
force = 1,
hjust = "right",
fontface = "bold",
size = 3.5,
nudge_x = .5,
direction = "y",
segment.color = "gray") +
geom_point(aes(fill = Entity), shape = 21, color="white", size = 2, stroke = 0.75, alpha = 1) +
# geom_text(aes(label = Maternal_Mortality_Ratio), color="black", size = 2.5, alpha = 1) +
geom_text_repel(aes(label = Maternal_Mortality_Ratio), color="black", size = 3.5, alpha = 1,
force = 1,
hjust = "center",
#fontface = "bold",
size = 3.0,
# nudge_x = 0,
direction = "y",
segment.color = "gray") +
scale_fill_manual(values = color_palette_asia) +
scale_color_manual(values = color_palette_asia) +
slope_specs +
labs(
title = "Maternal Mortality by Country in Asia",
subtitle = "Maternal deaths per 100,000 live births.",
caption = "source: Our World in Data"
)
girafe(ggobj = v1 + v2, width_svg = 25, height_svg = 15,
options = list(opts_sizing(rescale = TRUE, width = 1.0)))